1629. 按键持续时间最长的键
为保证权益,题目请参考 1629. 按键持续时间最长的键(From LeetCode).
解决方案1
Python
python
# 1629. 按键持续时间最长的键
# https://leetcode-cn.com/problems/slowest-key/
from typing import List
from collections import defaultdict
class Solution:
def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str:
maxK = ""
maxV = -1
for i in range(len(keysPressed)):
keyTime = releaseTimes[i] - (releaseTimes[i - 1] if i - 1 >= 0 else 0)
k = keysPressed[i]
v = keyTime
if v > maxV or (v == maxV and k > maxK):
maxV = v
maxK = k
return maxK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21